package com.source.hotelbath.popdialog;

import android.app.Dialog;
import android.content.Context;
import android.util.Log;
import android.view.Gravity;
import android.view.LayoutInflater;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.source.hotelbath.R;
import com.source.hotelbath.model.HodelBean;
import com.source.hotelbath.weight.PickerView;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by ZhouMeng on 2017/9/24.
 */

public abstract class HotelChooseListener implements View.OnClickListener,HotelSelcetItem{

    private Context context;

    TextView bt_queding;
    private RelativeLayout rl_date;
    private PickerView pickerView;
    private String hotel;
    private List<String> mDatas;
    private List<HodelBean> hodelBeanList=new ArrayList<>();
    private int position;

    public HotelChooseListener(Context context,List<HodelBean> hodelBeanList,int position) {
        super();
        this.context = context;
        this.hodelBeanList=hodelBeanList;
        this.position=position;
        initView();
        initDate();
        setListener();
    }




    /**
     * 显示时间
     */
    public void showTime() {
        if (builder == null) {
            builder = new Dialog(context, R.style.Theme_dialog);
            builder.setContentView(view);
            WindowManager wm = (WindowManager) context.getSystemService(Context.WINDOW_SERVICE);
            int width = wm.getDefaultDisplay().getWidth();
            Window window = builder.getWindow();
            // 重新设置
            WindowManager.LayoutParams lp = window.getAttributes();
            window.setGravity(Gravity.BOTTOM);
            lp.alpha = 1.0f; // 透明度
            lp.width = width;
            window.setAttributes(lp);
            builder.setCancelable(true);
            builder.setCanceledOnTouchOutside(true);
            builder.show();
        } else {
            builder.show();
        }
    }

    private void setListener() {
        //
        bt_queding.setOnClickListener(this);
//        rl_date.setOnClickListener(this);
    }

    Dialog builder;

    private void initView() {
        LayoutInflater inflater = (LayoutInflater) context
                .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        view = inflater.inflate(R.layout.hotel_select, null);
        pickerView = (PickerView) view.findViewById(R.id.pv_hotel);
        bt_queding = (TextView) view.findViewById(R.id.bt_queding);
//        rl_date = (RelativeLayout) view.findViewById(R.id.rl_date);
        mDatas=new ArrayList<>();
        for (int i = 0; i < hodelBeanList.size(); i++) {
            mDatas.add(hodelBeanList.get(i).getHotelName());
        }
        pickerView.setData(mDatas);
        pickerView.setSelected(position);

        pickerView.setOnSelectListener(new PickerView.onSelectListener() {
            @Override
            public void onSelect(String text, int mCurrentSelected) {
                hotel = text;
                position=mCurrentSelected;
            }
        });
    }

    View view;
    private TextView bt_quxiao;


    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.bt_queding:// 确定时间


                getItem(hotel,position);
                builder.dismiss();
                break;

//            case R.id.rl_date:
//                builder.dismiss();
//                break;
        }
    }

    private void initDate() {

    }


}
